#include <bits/stdc++.h>
#define File(xxx) freopen(xxx".in","r",stdin),freopen(xxx".out","w",stdout)
using namespace std;
typedef long long LL;
const int N = 1.5e6+5, mod = 1000000007;
int n, k, u, v, col[N], ans;
vector <int> to[N];
unordered_map <int, int> vis;

template <typename T> inline void debug(T x) { cerr<<x; }
template <typename T, typename ...T_> inline void debug(T x, T_ ...p) { cerr<<x<<' ', debug(p...); }
template <typename T> void read(T& x) {
	x = 0; int f = 0; char c = getchar();
	while(c < '0' || c > '9') f |= (c == '-'), c=getchar();
	while(c >= '0' && c <= '9') x=(x<<1)+(x<<3)+(c^48), c=getchar();
	x=(f ? -x : x);
}
int lne; char put[105];
template <typename T> void write(T x, char ch) {
	lne = 0; if(x < 0) putchar('-'), x=-x;
	do { put[++lne]=x%10, x/=10; } while(x);
	while(lne) putchar(put[lne--]^48);
	putchar(ch);
}
int dfs(int x, int fa, int dep, int fff) {
	if(dep == k) 
		return (fff != 1);
	int ret = 0;
	for(int y : to[x])
		if(y != fa) 
			ret|=dfs(y, x, dep+1, (fff+col[y]));
	return ret;
}
void rss(int x, int fa, int dep) {
	col[x]=(dep%k == 1);
	for(int y : to[x])
		if(y != fa) 
			rss(y, x, dep+1);
}
int upd(int x) {
	return (x >= mod ? x-mod : x);
}

signed main() {
	File("life");
	read(n), read(k);
	for(int i = 2; i <= n; ++i)
		read(u), read(v), to[u].push_back(v), to[v].push_back(u);
	int mx = 0;
	for(int i = 1; i <= n; ++i)
		mx=max(mx, (int) to[i].size());
	if(mx == 2) {
		puts("YES");
		write(k, '\n');
		return 0;
	}
	if(n <= 18) {
		for(int i = 1; i < (1<<n); ++i) {
			for(int j = 0; j < n; ++j)
				col[j+1]=((i>>j)&1);
			int pd = 0;
			for(int j = 1; j <= n; ++j)
				pd|=dfs(j, 0, 1, col[j]);
			if(!pd)
				++ans;
			// if(!pd) {
			// 	for(int j = 0; j < n; ++j)
			// 		debug((i>>j)&1);
			// 	debug('\n');
			// }
		}
		if(ans)
			puts("YES");
		else
			puts("NO");
		write(ans, '\n');
		return 0;
	}
	for(int i = 1; i <= n; ++i) {
		rss(i, 0, 1);
		int pd = 0, now = 0;
		for(int j = 1; j <= n; ++j)
			now=upd(3LL*now%mod+col[j]+1);
		if(vis.find(now) != vis.end()) continue;
		for(int j = 1; j <= n; ++j)
			pd|=dfs(j, 0, 1, col[j]);
		if(!pd)
			++ans, vis[now]=1;
	}
	if(ans)
		puts("YES");
	else
		puts("NO");
	write(ans, '\n');
	return 0;
}
